package com.woniuxy.project115.kaer.mall.controller;


import com.woniuxy.project115.kaer.commons.util.Result;
import com.woniuxy.project115.kaer.mall.service.ProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyc
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/productType")
@Api(tags = "商品类型接口")
public class ProductTypeController {
    @Resource
    private ProductTypeService productTypeService;

    /**
     *
     * @param productTypeName 商品类型名称
     * @param parentId 父类id
     * @return
     * @throws Exception
     */
    @ApiOperation("新增商品类型接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "productTypeName", value = "商品类型名称"),
                    @ApiImplicitParam(name = "parentId", value = "商品类型父id")
            }
    )
    @PostMapping("/addProductType")
    public Result addProductType(String productTypeName, Integer parentId) throws Exception {
        productTypeService.addProductType(productTypeName, parentId);
        return Result.succeed("新增成功");
    }

    /**
     *
     * @param typeId 类别id
     * @return
     * @throws Exception
     */
    //删除商品类别
    @PutMapping("/deleteProductType")
    @ApiOperation("删除商品类型接口")
    @ApiImplicitParam(name = "typeId", value = "商品类型id")
    public Result deleteProductType(Integer typeId) throws Exception {
        productTypeService.deleteProductType(typeId);
        return Result.succeed("删除成功");
    }
    //禁用or启用商品类别
    @ApiOperation("禁用or启用商品类型接口")
    @ApiImplicitParam(name = "typeId", value = "商品类型id")
    @PutMapping("/disableProductType")
    public Result disableProductType(Integer typeId) throws Exception {
        productTypeService.disableProductType(typeId);
        return Result.succeed("操作成功");
    }
}

